﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Framework;

namespace NLBS.Data.Business
{
   public class TrackBackData
    {
       private static readonly string TrackBackKey = "TrackBackKey";
       public static List<TrackBack> GetTrackBack()
       {
           ContentCache cache = ContentCache.Instantiate();
           List<TrackBack> lists = (List<TrackBack>)cache[TrackBackKey];
           if (lists == null)
           {
               lists = new List<TrackBack>(DbProvider.Instance().GetTrackBack());
               if (lists != null)
               {
                   cache.Insert(TrackBackKey, lists, CacheDuration.Long);
               }
           }
           return lists;
       }

       public static TrackBack GetTrackBackByID(int id)
       {

           return GetTrackBack().Find(delegate(TrackBack t)
           {
               return t.ID == id;
           });
       }

       public static TrackBack GetTrackBackByName(string title, string excerpt)
       {
           return GetTrackBack().Find(delegate(TrackBack t)
           {
               return t.Title == title && t.Excerpt == excerpt;
           });
       }

       public static void InsertTrackBack(TrackBack tb)
       {
           DbProvider.Instance().InsertTrackBack(tb);
           GetTrackBack().Insert(0, tb);
           new TrackBackFacade(tb, true);
       }

       public static void DeleteTrackBack(int id)
       {
           DbProvider.Instance().DeleteTrackBack(id);
           TrackBack tb = GetTrackBackByID(id);
           new TrackBackFacade(tb, false);
           GetTrackBack().Remove(tb);
       }
    }
}
